package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo13
{
    public static void main(String[] args)
    {
        try(Connection connection = DBUtil.getConnection())
        {
            connection.setAutoCommit(false);
            String sql = "insert into userinfo1 (username,password,nickname) values(?,?,?) ";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,"Aa");
            preparedStatement.setString(2,"132456");
            preparedStatement.setString(3,"little a");
            preparedStatement.executeUpdate();

            preparedStatement.setString(1,"Bb");
            preparedStatement.setString(2,"132456789");
            preparedStatement.setString(3,"little B");
            preparedStatement.executeUpdate();

            connection.commit();
            connection.rollback(); // 回滚后会删除两条数据，下次插入主键会从删除的开始


        }catch (SQLException e)
        {
            e.printStackTrace();
        }
    }
}
